import 'package:wechat_assets_picker/wechat_assets_picker.dart';

class AssetTypeUtils {
  // 解析出文件类型
  static AssetType parse(String url) {
    // 获取文件扩展名
    var extension = url.split(".").map((e) => e.toLowerCase());
    var imageExtensions = ['jpg', 'jpeg', 'gif', 'png'];
    var imageLen = imageExtensions.length;
    var videoExtensions = ['mp4', 'wmv', 'avi', 'mov'];
    var videoLen = videoExtensions.length;

    // 判断图片
    imageExtensions.addAll(extension);
    List<String> imageList = imageExtensions.toSet().toList();
    if (imageList.length < imageLen + extension.length) {
      return AssetType.image;
    }

    // 判断视频
    videoExtensions.addAll(extension);
    List<String> videoList = videoExtensions.toSet().toList();
    if (videoList.length < videoLen + extension.length) {
      return AssetType.video;
    }

    // 扩展名不在图片或视频数组中，返回null
    return AssetType.other;
  }
}
